# koroFileHeader at Home PC
# Create: 2021-04-11 09:50:19
# LastEdit: 2021-04-11 14:08:17
"""说明暂无"""
__author__ = '749B'

import os, sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
sys.path.append(BASE_DIR)

# pylint: disable = import-error
from azure_client import Azure_Client
from msrestazure.azure_cloud import AZURE_CHINA_CLOUD


def main():
    strQuery = "Resources | summarize count()"
    client = Azure_Client(AZURE_CHINA_CLOUD)
    name_len = 20
    
    subscriptions = client.get_subscriptions()
    for sub in subscriptions:
        print('("{name}", "{id}"),'.format(
            name=sub.get("display_name"), 
            id=sub.get("subscription_id")))

    res = client.resource_graph_query_default(strQuery, [sub.get("subscription_id") for sub in subscriptions])
    print("ALL".ljust(name_len), res.data[0].get("count_"))
    for sub in subscriptions:
        res = client.resource_graph_query_default(strQuery, [sub.get("subscription_id")])
        print(sub.get("display_name").ljust(name_len), res.data[0].get("count_"))


if __name__ == "__main__":
    from environs import Env
    env = Env()
    env.read_env()
    main()
